//
//  EMImageViewer.h
//  EMImageView
//
//  Created by EasonWang on 13-12-9.
//  Copyright (c) 2013年 EasonWang. All rights reserved.
//


#import <UIKit/UIKit.h>

typedef void(^EMImageViewerOpeningBlock)(void);
typedef void(^EMImageViewerClosingBlock)(void);


@class EMImageViewer;

@protocol EMImageViewerDelegate <NSObject>

@required
/**
 从数据源获取到图片的个数
 @param imageViewer imageview的视图管理器
 @return 返回图片的个数
 */
- (NSInteger) numberImagesFromImageViewer:(EMImageViewer*)imageViewer;

/**
 获取将要用于在图片浏览器中展示的图片视图(imageView)
 */
- (NSMutableArray *)getImageViewArray;


@optional
/**
 获取数据源的图片
 */
- (UIImage *)getImageFromDatasource:(UIImage*)image;


@end

@interface EMImageViewer : UIViewController

@property (weak, readonly, nonatomic) UIViewController *rootViewController;
/** senderView，视图发送者，为 UIImageView(EMImageView) 对象 */
@property (nonatomic, strong) UIImageView *senderView;
/** openingBlock */
@property (nonatomic, weak) EMImageViewerOpeningBlock openingBlock;
/** closingBlock */
@property (nonatomic, weak) EMImageViewerClosingBlock closingBlock;
/** 初始下标 */
@property (nonatomic, assign) NSInteger initialIndex;
/** 图片数据源（及delegate） */
@property (nonatomic, weak) id<EMImageViewerDelegate> imageDatasource;

/** 
 显示图片浏览器，及图片浏览器本质上为UIViewController，并将图片浏览器作为rootViewController的subViewController
 */
- (void)presentImageViewer;

@end


#pragma mark - UIImageView Category

@interface UIImageView (EMImageViewer)

/**
 对imageview添加手势监听，此方法为UIImageView的扩展方法，可对imageview进行点击监听，并进行相对应的响应
 @param imageDatasource 图片数据源的代理(delegate)，需先实现EMImageViewerDelegate委托
 @param initialIndex 初始化下标，及为即将在图片浏览器中显示的图片的下标
 @param open EMImageViewerOpeningBlock的对象，图片浏览器启动后将执行此block，可以在此block中对浏览器打开后的操作
 @param close EMImageViewerClosingBlock对象，图片浏览器退出后将执行此block，可以在此block中对图片浏览器退出后的操作
 */
- (void)setupImageViewerWithDataSource:(id<EMImageViewerDelegate>)imageDatasource
                          initialIndex:(NSInteger)initialIndex
                                onOpen:(EMImageViewerOpeningBlock)open
                               onClose:(EMImageViewerClosingBlock)close;


@end